package com.sfh.appversion.controller;

import com.sfh.appversion.base.Result;
import com.sfh.appversion.base.page.PageResponse;
import com.sfh.appversion.dao.entity.AppInfoDO;
import com.sfh.appversion.dao.entity.AppVersionAssignDO;
import com.sfh.appversion.dao.entity.AppVersionDO;
import com.sfh.appversion.dto.req.*;
import com.sfh.appversion.dto.resp.AppMenuRespDTO;
import com.sfh.appversion.dto.resp.AppVersionCheckRespDTO;
import com.sfh.appversion.server.AppServer;
import com.sfh.appversion.server.AppVersionServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * 应用
 */
@RestController
@RequestMapping("/appversion")
public class AppVersionController {


    @Autowired
    private AppVersionServer appVersionServer;

    /***
     * 新增应用版本
     * @param vo
     */
    @PostMapping("add")
    public Result<Boolean> add(@RequestBody AppVersionNewReqDTO vo) {

        boolean success = appVersionServer.add(vo);
        return Result.success(success);
    }

    /***
     *  更新应用版本发布状态
     */
    @PostMapping("editStatue")
    public Result<Boolean> editStatue(@RequestBody AppVersionEditReqDTO req) {
        return Result.success(appVersionServer.editStatue(req.getVersionId(), req.getVersionStatue()));
    }

    /***
     *  更新应用版本强制更新状态
     */
    @PostMapping("editForce")
    public Result<Boolean> editForce(@RequestBody AppVersionEditReqDTO req) {
        return Result.success(appVersionServer.editForce(req.getVersionId(), req.getVersionForce()));
    }

    /***
     * 删除应用版本
     */
    @PostMapping("delete/{appId}")
    public Result<Boolean> delete(@PathVariable String versionId) {
        return Result.success(appVersionServer.del(versionId));
    }

    /***
     * 删除应用全部版本
     */
    @PostMapping("delAll")
    public Result<Boolean> delAll(String appId) {
        return Result.success(appVersionServer.delAll(appId));
    }




    /***
     *  编辑发布模式
     */
    @PostMapping("editReleaseType")
    public Result<Boolean> editReleaseType(AppVersionEditReqDTO reqDTO) {
        return Result.success(appVersionServer.editReleaseType(reqDTO));
    }

    /***
     *  新增版本指定更新人员
     */
    @PostMapping("addAssignPerson")
    public Result<Boolean> addAssignPerson(AppVersionAssignNewReqDTO reqDTO) {
        return Result.success(appVersionServer.addAssignPerson(reqDTO));
    }

    /***
     *  删除版本指定更新人员
     */
    @PostMapping("delAssignPerson")
    public Result<Boolean> delAssignPerson(String assignId) {
        return Result.success(appVersionServer.delAssignPerson(assignId));
    }

    /***
     * 编辑版本指定更新人员更新状态
     */
    @PostMapping("editAssignPersonStatue")
    public Result<Boolean> editAssignPersonStatue(String assignId, String assignStatue) {
        return Result.success(appVersionServer.editAssignPersonStatue(assignId, assignStatue));
    }

    /***
     * 应用版本分页
     * @return
     */
    @PostMapping("queryPage")
    public Result<PageResponse<AppVersionDO>> queryPage(@RequestBody AppVersionPageReqDTO req) {
        return Result.success(appVersionServer.queryPage(req));
    }

    /***
     * 查询版本指定更新人员
     * @param vo
     */
    @PostMapping("queryAssignPersonPage")
    public Result<PageResponse<AppVersionAssignDO>> queryAssignPersonPage(AppVersionAssignReqDTO vo) {
        return Result.success(appVersionServer.queryAssignPersonPage(vo));
    }

    /***
     * 检查最新版本
     * @param vo
     */
    @PostMapping("checkNewVersion")
    public Result<AppVersionCheckRespDTO> checkNewVersion(AppVersionCheckReqDTO vo) {
        return Result.success(appVersionServer.checkNewVersion(vo));
    }


}
